import axios from 'axios'
// 一些请求的基本配置
let baseUrl = window.PLATFROM_CONFIG.baseUrl
const service = axios.create({
	// baseURL: "https://whr.microger.com:18223",// 接口的域名地址
    baseURL: baseUrl,// 接口的域名地址
    // baseURL: "http://localhost:8007",// 接口的域名地址
	headers: {
		// 'Content-Type':'application/json;charset=UTF-8',
        'Access-Control-Allow-Origin': '*',
        "Access-Control-Allow-Methods": "PUT,POST,GET,DELETE,OPTIONS",
        "Access-Control-Allow-Headers": 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild',
        "X-Powered-By": ' 3.2.1',
        "Content-Type": "application/json;charset=utf-8",
        // "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
		// 'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8',
		// 'Authorization':'f00c246c-faa0-4098-8654-c4c3eab30eee',
		// 'entpId':'2020042524320001'
	}
})

// 输出方法
export default function request(url, data = {}, entpId, Authorization, method = 'post') {
	return new Promise((resolve, reject) => {
		const options = {
			url,
			method,
			headers: {
				'Authorization': Authorization,
				'entpId': entpId,
			}
		}
		if (method.toLowerCase() === 'get') {
			options.params = data
		} else {
			options.data = data
		}
		let page = window.localStorage.page

		let arr = url.split('/')
		let jsonName = arr[arr.length - 1]
		if (url === "/api/v3/screen/blockchain/queryScreenBcInfo"){
		}else if(url==="/app/mnyc/price/getGoodsFuturePriceList"){

		}else if(url === "/loginScreen"){

		}
		else{
			import(`../data${page}/${jsonName}.json`).then(res => {
				resolve(res)
			})
			return;
		}
		
		service(options)
			.then(res => {
				resolve(res.data)
			})
			.catch(error => {
				reject()
			})
		
	})
}
